/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vehicle.bol;

import gmail.SendMailOk;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Random;
import vehicle.dal.DAL;

/**
 *
 * @author caodangtinh
 */
public class ResetPassword {

    SendMailOk smo = new SendMailOk();

    /*
     * random pass
     */
    public String randomPass() {
        Random random = new Random();
        return String.valueOf(random.nextInt(9999999));
    }
    /*
     * Send random pass
     */

    public void sendRandomPass(String email) {
        SendMailOk.sendMail(email, "New Password", randomPass());

    }
    /*
     * Check email exist
     */

    public boolean checkEmail(String email) {
        boolean flag = false;
        try {
            DAL dal = new DAL();
            ArrayList paramlist = new ArrayList();
            paramlist.add(email);
            ResultSet rs = dal.executeQuery("checkEmail", paramlist);
            if (rs.next()) {
                flag = true;
            }
        } catch (Exception e) {
        }
        return flag;
    }
    /*
     * update new pass
     */
    public void UpdatePass(String email)
    {
        try {
            DAL dal = new DAL();
            ArrayList paramlist = new ArrayList();
            paramlist.add(email);
            paramlist.add(randomPass());
            dal.executeUpdateQuery("updatePassword", paramlist);
        } catch (Exception e) {
        }
    }
}
